package com.tuozixuan.javafx.control;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class TreeVeiwDemo extends Application {

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {

		TreeView<String>  treeView = new TreeView<String>();
		TreeItem<String> root = new TreeItem<>("动物");
		treeView.setRoot(root);

		TreeItem<String> birdTree = new TreeItem<>("鸟类");
		birdTree.getChildren().add(new TreeItem<>("麻雀"));
		birdTree.getChildren().add(new TreeItem<>("乌鸦"));
		birdTree.getChildren().add(new TreeItem<>("燕子"));
		root.getChildren().add(birdTree);

		TreeItem<String> mammalTree = new TreeItem<>("哺乳类");
		mammalTree.getChildren().add(new TreeItem<String>("猫"));
		mammalTree.getChildren().add(new TreeItem<String>("狗"));
		mammalTree.getChildren().add(new TreeItem<String>("兔子"));
		root.getChildren().add(mammalTree);

		VBox vbox = new VBox();
		vbox.getChildren().addAll(treeView);

		Scene scene = new Scene(vbox, 300, 300);

		primaryStage.setScene(scene);
		primaryStage.sizeToScene();
		primaryStage.show();
	}

}
